package logic

import (
	"context"
	"tieba/tiebarpc/tiebarpc"

	"tieba/api/internal/svc"
	"tieba/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForgetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewForgetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgetLogic {
	return &ForgetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ForgetLogic) Forget(req *types.ForgetRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	forget, err := l.svcCtx.TieBaRpc.Forget(l.ctx, &tiebarpc.ForgetRequest{
		Mobile:   req.Mobile,
		SendCode: req.SendCode,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改密码成功",
		Data:    forget,
	}, nil
	return
}
